<?php

class Controller_Picmaterial extends Controller_Abstract
{
    function actionIndex()
    {
    	$currAlbumId = $this->_context->get('albumId', 0);
    	
    	$picsConstraint = array('getFilePath' => true);
    	$currAlbum = array();
    	if($currAlbumId > 0){
    		$currAlbum = Albums::model()->find('*', array('id' => $currAlbumId), array('onlyOne' => true));
    		$this->_view['currAlbum'] = $currAlbum;
    		$this->_view['brotherAlbums'] = Albums::model()->find(
    			'*', 
    			array('parent_id' => $currAlbum['parent_id']), 
    			array('getCoverPicture' => true, 'getCoverPictureFilePath' => true),
    			array('id != ?'),
    			array($currAlbumId)
    		);
    		$this->_view['parentAlbums'] = Albums::model()->find(
    			'*', 
    			array('id' => $currAlbum['parent_id']), 
    			array('getCoverPicture' => true, 'getCoverPictureFilePath' => true)
    		);
    		
    		$this->_view['sonPics'] = Pictures::model()->find('*', array('albumid' => $currAlbumId), $picsConstraint);
    	}else{
    		$picsConstraint['orderBy'] = array(
				'fields' => array('created_int'), 
				'seq' => array('DESC')
			);
			$picsConstraint['limit'] = PICS_DEFAULT_SHOWNUM;
			
    		$this->_view['sonPics'] = Pictures::model()->find('*', null, $picsConstraint);
    	}
    	
    	$this->_view['sonAlbums'] = Albums::model()->find('*', array('parent_id' => $currAlbumId), array('getCoverPicture' => true, 'getCoverPictureFilePath' => true));
    	
    	$this->_createCrumbs($currAlbum);
    }
    
    protected function _createCrumbs($currAlbum)
    {
    	$this->_view['crumbs']['图片素材'] = '';
    	
		if(!empty($currAlbum['id'])){
			$this->_view['crumbs']['图片素材'] = url('picmaterial/index');
			
			$albumAllSimple = Albums::model()->find();
			$nodesOfTrubkTree = Albums::model()->getTrunkOfNode($albumAllSimple, $currAlbum['id'], 'justArray');
			
			foreach($nodesOfTrubkTree as $node){
				$this->_view['crumbs'][$node['name']] = url('picmaterial/index', array('albumId' => $node['id']));
			}
			
			$this->_view['crumbs'][$currAlbum['name']] = '';
		}
    }
    
    
    
}